#include "Faculty.h"


Faculty_t::Faculty_t(University_t* pUV) : Observer(pUV){
	m_pUV = pUV;
	pUV->Attach(this);
	price = pUV->getPrice();
}

void	Faculty_t::Update(Subject* pChangedSbj){

	if ((void*)pChangedSbj == (void*)m_pUV){
		int p = m_pUV->getPrice();
		if (p != price) {
			price = p;
		}
		else{
			Notify(); //inform students that a lecture was canceled.
		}
	}
}

void Faculty_t::destroyStudent(Student_t* student) {
	m_pUV->Detach(student);
	Detach(student);
	delete student;
   	return;
}

Faculty_t::~Faculty_t(){
	destroyAllStudents();
	m_pUV->Detach(this);
	return;
}

void Faculty_t::destroyAllStudents(){
	for (unsigned int i = 0;i < m_observers.size() ;++i)
	{
		m_pUV->Detach((m_observers)[i]);
		delete (m_observers)[i];
	}
	return;
}

ExactSciencesFaculty::ExactSciencesFaculty(University_t* pUV) : Faculty_t(pUV){}

Student_t* ExactSciencesFaculty::createStudent()
{
	
	Student_t *student = new Student_t(new ESF_Student(m_pUV,this,m_pUV->getPrice()), m_pUV);
	m_pUV->Attach(student);
	Attach(student);
	return student;
}


FacultyOfHumanities::FacultyOfHumanities(University_t* pUV) : Faculty_t(pUV){}

Student_t* FacultyOfHumanities::createStudent() 
{

	Student_t *student = new Student_t(new FOH_Student(m_pUV,this,m_pUV->getPrice()), m_pUV);
	m_pUV->Attach(student);
	Attach(student);
	return student;
}